/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MemberDetails;

import java.io.*;
import java.sql.ResultSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.*;

/**
 *
 * @author Bharath
 */
public class GetDates extends HttpServlet {

    GetDatesDao gdd;

    public GetDates() {
        gdd = new GetDatesDao();
    }

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, Exception {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String dfrom = request.getParameter("datefrom");
        try {
            if (request.getParameter("bday") != null)
            {  System.out.println("in bday if condition");
                ResultSet rs = gdd.getdates(dfrom);
                System.out.println("Result rs value is" + rs);
                if (rs.next() == true) {
                    HttpSession hsdates = request.getSession(true);
                    hsdates.setAttribute("dfrom", dfrom);
                    request.getRequestDispatcher("dates1.jsp").forward(request, response);
                } else {
                    out.println("<script language='javascript'>alert('No Entries');location = 'dates.jsp';</script>");
                }
            }
            if (request.getParameter("aniv") != null)
            {
                System.out.println("$$$$$$in bday if condition");
                ResultSet rs1 = gdd.get_aniv_dates(dfrom);
                System.out.println("Result rs value is" + rs1);
                if (rs1.next() == true) {
                    HttpSession hsdates = request.getSession(true);
                    hsdates.setAttribute("dfrom", dfrom);
                    request.getRequestDispatcher("dates2.jsp").forward(request, response);
                } else {
                    out.println("<script language='javascript'>alert('No Entries');location = 'dates.jsp';</script>");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(GetDates.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(GetDates.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
